package com.itbaizhan.mapper;

import com.itbaizhan.pojo.Student;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface StudentMapper {

    @Select("select * from student")
    //自定义映射关系
    @Results(id = "studentMapper",value={
            @Result(id = true,property = "sid",column = "sid"),
            @Result(property = "name",column = "name"),
            @Result(property = "age",column = "age"),
            @Result(property = "sex",column = "sex"),
            /**
             * property:属性名
             * column:调用从表方法传入的参数列
             * one:表示该属性是一个对象
             * select:调用的从表方法
             * fetchType:加载方式
             */
            @Result(property = "classes",column = "classId",
                    one = @One(select = "com.itbaizhan.mapper.ClassesMapper.findByCid",
                    fetchType = FetchType.EAGER))

    })
    List<Student> findAll();

    //根据班级ID查询学生
    @Select("select * from student where classId = #{classId}")
    List<Student> findByClassId(Integer classId);
}
